/*package com.irdstudio.efp.esb.api.rest.ms;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.irdstudio.efp.console.service.facade.PrdAdaptedSoltService;
import com.irdstudio.efp.console.service.facade.PrdInfoService;
import com.irdstudio.efp.console.service.facade.PubSysInfoService;
import com.irdstudio.efp.console.service.vo.PrdAdaptedSoltVO;
import com.irdstudio.efp.console.service.vo.PrdInfoVO;
import com.irdstudio.efp.cus.service.facade.CusIndivService;
import com.irdstudio.efp.esb.api.bean.nls.ReqLoanAppBean;
import com.irdstudio.efp.esb.api.bean.nls.RespLoanAppBean;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.efp.esb.common.constant.MsLoanConstant;
import com.irdstudio.basic.framework.core.constant.BaseConstant;
import com.irdstudio.basic.framework.core.exception.BizException;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.basic.framework.core.util.DateUtility;
import com.irdstudio.basic.framework.core.util.MessageRuleCheckUtil;
import com.irdstudio.basic.framework.core.util.StringUtil;
import com.irdstudio.basic.framework.core.util.ValidationUtils;
import com.irdstudio.efp.nls.common.constant.PrdAdaptedSoltEnums;
import com.irdstudio.efp.nls.common.constant.QueueTaskEnums;
import com.irdstudio.efp.nls.common.util.PrdQueueSlotUtils;
import com.irdstudio.efp.nls.service.facade.NlsApplyInfoService;
import com.irdstudio.efp.nls.service.facade.NlsApplyRelationService;
import com.irdstudio.efp.nls.service.facade.queue.NlsProcessBizService;
import com.irdstudio.efp.nls.service.facade.queue.NlsQueueTaskService;
import com.irdstudio.efp.nls.service.vo.NlsApplyInfoVO;
import com.irdstudio.efp.nls.service.vo.NlsApplyRelationVO;
import com.irdstudio.efp.nls.service.vo.queue.NlsProcessBizVO;
import com.irdstudio.efp.nls.service.vo.queue.NlsQueueTaskVO;

*//**
 * 马上申请审批服务接口逻辑处理类
 * 
 * @author heyingfeng
 * @since 2018年12月18日 下午8:37:48
 * @version 1.0
 *//*
@RestController
@RequestMapping("/esb")
@Deprecated
public class MsLoanController {

	private static Logger logger = LoggerFactory.getLogger(MsLoanController.class);

	*//**
	 * 马上申请审批服务接口逻辑处理方法，处理逻辑包括：<br>
	 * 1.对用户请求domain中值做是否必输性校验；<br>
	 * 2.对用户请求domain中值做是否合规性校验；<br>
	 * 3.调用对应的中台服务；<br>
	 * 1.1：增加调用队列任务表信息
	 * 
	 * @param esbReqBodyBean
	 * @return
	 * @throws ESBException
	 * @throws Exception
	 * @author heyingfeng
	 * @author huangwb
	 * @since 2018年12月18日 下午8:55:31
	 * @version 1.1
	 *//*
	@PostMapping("/SERVICE_40130003_01/01020001")
	public RespLoanAppBean initNlsApplyInfo(ReqLoanAppBean reqLoanAppBean) throws ESBException, Exception {
		RespLoanAppBean respLoanAppBean = new RespLoanAppBean();
		try {
			// 3.必输项校验（下面注释的字段，暂时表没有）
			// 3.1.接口字段必输项校验
			String applSeq = reqLoanAppBean.getAppFlowNo();
			String cusName = reqLoanAppBean.getBrwNm();
			String certType = reqLoanAppBean.getCertTp();
			String certNo = reqLoanAppBean.getCertNo();
			String certAddr = reqLoanAppBean.getCertAddr();
			String mobile = reqLoanAppBean.getMblNo();
			String prdCde = reqLoanAppBean.getProdCd();
			String prdName = reqLoanAppBean.getLoanProdNm();
			String loanAmt = reqLoanAppBean.getLoanAmt();
			String loanTerm = reqLoanAppBean.getLoanTrm();
			String loanTermType = reqLoanAppBean.getTrmType();
			String ethnic = reqLoanAppBean.getEthnic();
			String edu = reqLoanAppBean.getEdu();
			String wrkCorpNm = reqLoanAppBean.getWrkCorpNm();
			String wrkCorpAddr = reqLoanAppBean.getWrkCorpAddr();
			String mrgSitu = reqLoanAppBean.getMrgSitu();
			String spsNm = reqLoanAppBean.getSpsNm();
			String ttl = reqLoanAppBean.getTtl();
			// 3.2.字段值合规性校验
			MessageRuleCheckUtil.validateIdNo18(certNo);// 身份证
			boolean flag = ValidationUtils.validPhoneNum("0", mobile);// 手机号
			if (flag == false) {
				throw new BizException("手机号错误");
			}
			MessageRuleCheckUtil.checkDouble(loanAmt, "贷款金额");
			MessageRuleCheckUtil.checkInteger(loanTerm, "贷款期限");
			if (!StringUtil.isMatches(prdName)) {
				throw new BizException("产品名称格式错误");
			}
			// // 3.3.验证客户是否存在
			// 根据身份证获取客户号
			String cusId = cusIndivService.getCusIdByCertCode(certType, certNo);
			if (cusId == null) {
				cusId = "";
			}
			// 根据产品代码查询产品id
			PrdInfoVO vo = new PrdInfoVO();
			vo.setPrdCode(prdCde);
			PrdInfoVO outputVo = prdInfoService.queryLastPrdInfo(vo);
			if (outputVo == null || "".equals(outputVo.getPrdId())) {
				throw new BizException("无产品id");
			}
			// 3.4.调用中台服务
			// 插入网贷申请基本信息表
			NlsApplyInfoVO nlsApplyInfoVO = new NlsApplyInfoVO();
			// Zztest00001
			nlsApplyInfoVO.setApplySeq(applSeq);// 流水号
			nlsApplyInfoVO.setCusId(cusId);// 客户id
			// 张泽
			nlsApplyInfoVO.setCusName(cusName);// 姓名
			// 10100
			nlsApplyInfoVO.setCertType(certType);// 证件类型
			// 430103199912123530
			nlsApplyInfoVO.setCertCode(certNo);// 证件号码
			// 地址
			nlsApplyInfoVO.setIndivRsdAddr(certAddr);
			// 湖南省长沙市************
			nlsApplyInfoVO.setIndivRsdAddr(reqLoanAppBean.getCertAddr() == null ? "" : reqLoanAppBean.getCertAddr());// 证件地址
			// 20110101-20210101
			nlsApplyInfoVO.setIndivIdExpDt(reqLoanAppBean.getCertMatureDt() == null ? "" : reqLoanAppBean.getCertMatureDt());// 证件到期日
			// 18577004444
			nlsApplyInfoVO.setMobile(mobile);// 手机号码
			nlsApplyInfoVO.setPrdId(outputVo.getPrdId());// 产品id
			// 01020001
			nlsApplyInfoVO.setPrdCode(prdCde);// 产品代码
			// 马上联合贷
			nlsApplyInfoVO.setPrdName(prdName);// 产品名称
			// 1
			nlsApplyInfoVO.setCusGender(reqLoanAppBean.getBrwGnd() == null ? "" : reqLoanAppBean.getBrwGnd());// 性别
			// CHN
			nlsApplyInfoVO.setCusNational(reqLoanAppBean.getNation() == null ? "CHN" : reqLoanAppBean.getNation());// 国籍
			// Z
			nlsApplyInfoVO.setProfession(reqLoanAppBean.getCrr() == null ? "" : reqLoanAppBean.getCrr());// 职业

			// 10000.00
			nlsApplyInfoVO.setApplyAmt(new BigDecimal(loanAmt));// 贷款金额
			// 12
			nlsApplyInfoVO.setLoanTerm(loanTerm);// 贷款期限
			// M
			nlsApplyInfoVO.setLoanTermType(loanTermType);// 期限类型
			// 006
			nlsApplyInfoVO.setLoanPurpose(reqLoanAppBean.getBrwUsg() == null ? "" : reqLoanAppBean.getBrwUsg());// 借款用途

			nlsApplyInfoVO.setRecvAcctNo(reqLoanAppBean.getBankCardNo() == null ? "" : reqLoanAppBean.getBankCardNo());// 银行卡号

			nlsApplyInfoVO.setRecvBankName(reqLoanAppBean.getBankNm() == null ? "" : reqLoanAppBean.getBankNm());// 银行卡号

			nlsApplyInfoVO.setApplyDate(pubSysInfoService.getOpenday(BaseConstant.SYS_ID_1001));// 申请日期（营业日期）
			nlsApplyInfoVO.setApplyTime(DateUtility.getCurrAppDateTimeString());// 申请时间（当前机器时间）
			nlsApplyInfoVO.setCreateUser(nlsApplyInfoVO.getLoginUserId());// 创建人
			nlsApplyInfoVO.setCreateTime(DateUtility.getCurrAppDateTimeString());// 创建时间
			nlsApplyInfoVO.setLastModifyUser(nlsApplyInfoVO.getLoginUserId());// 最后修改人
			nlsApplyInfoVO.setLastModifyTime(DateUtility.getCurrAppDateTimeString());// 最后修改时间
			nlsApplyInfoVO.setNlsApplyState(MsLoanConstant.NlsApplyStateEnum.APPR.VALUE);// 处理中
			*//** add by wangyk start **//*
			nlsApplyInfoVO.setEthnic(ethnic);
			nlsApplyInfoVO.setEdu(edu);
			nlsApplyInfoVO.setWrkCorpNm(wrkCorpNm);
			nlsApplyInfoVO.setWrkCorpAddr(wrkCorpAddr);
			nlsApplyInfoVO.setMrgSitu(mrgSitu);
			nlsApplyInfoVO.setSpsNm(spsNm);
			nlsApplyInfoVO.setTtl(ttl);
			nlsApplyInfoVO.setBrthDt(reqLoanAppBean.getBrthDt());
			nlsApplyInfoVO.setWrkCorpTel(StringUtil.replaceNullByObj(reqLoanAppBean.getWrkCorpTel()));
			nlsApplyInfoVO.setFamAddr(StringUtil.replaceNullByObj(reqLoanAppBean.getFamAddr()));
			nlsApplyInfoVO.setAplCmmAddr(StringUtil.replaceNullByObj(reqLoanAppBean.getAplCmmAddr()));
			nlsApplyInfoVO.setFamTelNo(StringUtil.replaceNullByObj(reqLoanAppBean.getFamTelNo()));
			nlsApplyInfoVO.setMblTelNo(StringUtil.replaceNullByObj(reqLoanAppBean.getMblNo()));
			nlsApplyInfoVO.setIndvIncmAmt(StringUtil.replaceNullByObj(reqLoanAppBean.getIndvIncmAmt()).equals("") ? BigDecimal.ZERO
					: new BigDecimal(reqLoanAppBean.getIndvIncmAmt()));
			nlsApplyInfoVO.setFamIncmAmt(StringUtil.replaceNullByObj(reqLoanAppBean.getFamIncmAmt()).equals("") ? BigDecimal.ZERO
					: new BigDecimal(reqLoanAppBean.getFamIncmAmt()));
			nlsApplyInfoVO.setSpsCtcTelNo(StringUtil.replaceNullByObj(reqLoanAppBean.getSpsCtcTelNo()));
			nlsApplyInfoVO.setSpsMblTelNo(StringUtil.replaceNullByObj(reqLoanAppBean.getSpsMblTelNo()));
			nlsApplyInfoVO.setPstcd(StringUtil.replaceNullByObj(reqLoanAppBean.getPstcd()));
			nlsApplyInfoVO.setWhthrFrmr(StringUtil.replaceNullByObj(reqLoanAppBean.getWhthrFrmr()));
			nlsApplyInfoVO.setCorpChar(StringUtil.replaceNullByObj(reqLoanAppBean.getCorpChar()));
			*//** add by wangyk end **//*
			int num1 = nlsApplyInfoService.insertNlsApplyInfo(nlsApplyInfoVO);
			// 插入网贷申请联系人信息表
			NlsApplyRelationVO nlsApplyRelationVo = new NlsApplyRelationVO();
			nlsApplyRelationVo.setRelApptSeq("");// 主键流水号
			nlsApplyRelationVo.setApplySeq(applSeq);// 申请流水号
			nlsApplyRelationVo.setCusId(cusId);// 客户id
			nlsApplyRelationVo.setCusName(cusName);// 姓名
			nlsApplyRelationVo.setCertType(certType);// 证件类型
			nlsApplyRelationVo.setCertCode(certNo);// 证件号码
			nlsApplyRelationVo.setRelName(reqLoanAppBean.getCtcPrsnNm() == null ? "" : reqLoanAppBean.getCtcPrsnNm());// 联系人姓名
			nlsApplyRelationVo.setRelRelation(reqLoanAppBean.getCtcPrsnRela() == null ? "" : reqLoanAppBean.getCtcPrsnRela());// 联系人关系
			nlsApplyRelationVo.setCreateTime(DateUtility.getCurrAppDateTimeString());// 创建时间
			nlsApplyRelationVo.setLastChgTime(DateUtility.getCurrAppDateTimeString());// 最后修改时间
			int num2 = nlsApplyRelationService.insertNlsApplyRelation(nlsApplyRelationVo);
			// 插入队列任务表中
			NlsQueueTaskVO inNlsQueueTaskVo = new NlsQueueTaskVO();
			inNlsQueueTaskVo.setApplySeq(applSeq);// 申请流水号
			inNlsQueueTaskVo.setPrdId(outputVo.getPrdId());// 产品ID
			inNlsQueueTaskVo.setPrdCode(prdCde);// 产品代码
			inNlsQueueTaskVo.setPrdName(prdName);// 产品名称
			inNlsQueueTaskVo.setCusId(cusId);// 客户号
			inNlsQueueTaskVo.setCusName(cusName);// 客户名称
			inNlsQueueTaskVo.setQueueTaskState(QueueTaskEnums.QueueTaskStateEnum.EXECUTORY.getCode());// 队列任务状态
			inNlsQueueTaskVo.setHangTimes(QueueTaskEnums.QueueHangTimesEnum.INITIALIZE.getTimes());// 挂起次数
			inNlsQueueTaskVo.setConsumerId(QueueTaskEnums.QueueConsumerIdEnum.QUEUE.getConsumerCode());// 消费方标识
			inNlsQueueTaskVo.setCreateTime(DateUtility.getCurrAppDateTimeString());// 创建时间
			inNlsQueueTaskVo.setLastModifyTime(DateUtility.getCurrAppDateTimeString());// 最近修改时间
			int num3 = nlsQueueTaskService.insertNlsQueueTask(inNlsQueueTaskVo);
			// 查询产品插槽表
			PrdAdaptedSoltVO prdAdaptedSoltVo = new PrdAdaptedSoltVO();
			prdAdaptedSoltVo.setPrdId(outputVo.getPrdId());
			prdAdaptedSoltVo.setSoltState(PrdAdaptedSoltEnums.SlotStateEnum.ON.getCode());// 插槽状态
			List<PrdAdaptedSoltVO> prdAdaptedSoltVoList = prdAdaptedSoltService.queryByPrdIdAndState(prdAdaptedSoltVo);
			Objects.requireNonNull(prdAdaptedSoltVoList);

			// 插入网贷业务过程表
			NlsProcessBizVO inNlsProcessBizVo = new NlsProcessBizVO();
			inNlsProcessBizVo.setApplySeq(applSeq);// 申请流水号
			inNlsProcessBizVo.setCusId(cusId);// 客户编号
			inNlsProcessBizVo.setCusName(cusName);// 客户名称
			inNlsProcessBizVo.setPrdId(outputVo.getPrdId());// 产品ID
			inNlsProcessBizVo.setPrdCode(prdCde);// 产品代码
			inNlsProcessBizVo.setPrdName(prdName);// 产品名称
//			inNlsProcessBizVo.setSoltApplyIn(PrdAdaptedSoltEnums.SoltProcessStateEnum.SUCCESS.getCode());// 通过
			inNlsProcessBizVo.setHangTimes(QueueTaskEnums.QueueHangTimesEnum.INITIALIZE.getTimes());

			for (int i = 0; i < prdAdaptedSoltVoList.size(); i++) {
				PrdAdaptedSoltVO prdAdaptedSolt = prdAdaptedSoltVoList.get(i);
				String prdId = prdAdaptedSolt.getPrdId();
				String soltCode = prdAdaptedSolt.getSoltCode();
				String soltName = prdAdaptedSolt.getSoltName();
				String soltService = prdAdaptedSolt.getSoltService();// 插槽服务类，此处指注册到dubbo中的实现类
				int soltOrder = prdAdaptedSolt.getSoltOrder();
				// 校验产品插槽中的产品ID、插槽代码、插槽名称、插槽服务和顺序是否正确，不正确则抛出异常
				boolean checkFlag = PrdQueueSlotUtils.checkAdaptedSoltInfo(prdId, soltCode, soltName, soltService, soltOrder);
				if (checkFlag == false) {
					logger.error("产品插槽中的产品ID【" + prdId + "】插槽代码【" + soltCode + "】插槽名称【" + soltName + "】插槽服务【" + soltService + "】和顺序【"
							+ soltOrder + "】错误，请检查.");
					throw new Exception("产品插槽中的产品ID【" + prdId + "】插槽代码【" + soltCode + "】插槽名称【" + soltName + "】插槽服务【" + soltService + "】和顺序【"
							+ soltOrder + "】错误，请检查.");
				}
				// 根据插槽代码 映射
				Field field = NlsProcessBizVO.class.getDeclaredField(soltCode);
				field.setAccessible(true);
				// 更新该插槽状态为待执行
				field.set(inNlsProcessBizVo, PrdAdaptedSoltEnums.SoltProcessStateEnum.EXECUTORY.getCode());
			}
			inNlsProcessBizVo.setCreateTime(DateUtility.getCurrAppDateTimeString());// 创建时间
			inNlsProcessBizVo.setLastModifyTime(DateUtility.getCurrAppDateTimeString());// 最后修改时间
			inNlsProcessBizVo.setCreateDate(DateUtility.getCurrAppDateStr());// 创建日期
			nlsProcessBizService.insertNlsProcessBiz(inNlsProcessBizVo);
			// 3.5异步调用节点
			// 3.6组装返回报文
			if (num1 == -1 || num2 == -1 || num3 == -1) {
				respLoanAppBean.setRetStCd(EsbBizEnums.RetCodeEnum.FAILURE.getVALUE());
				respLoanAppBean.setRtnMsg("插入数据表异常!");
			} else {
				respLoanAppBean.setRetStCd(EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE());
				respLoanAppBean.setRtnMsg("交易成功");
			}
			respLoanAppBean.setBankInWrongCd("");
			respLoanAppBean.setBankInWrongRsn("");
			respLoanAppBean.setSynDistrFlg("");
			respLoanAppBean.setLoanOrdrNo(applSeq);
			respLoanAppBean.setBankCustNo("");
		} catch (ESBException e) {
			logger.error("马上申请审批服务接口处理失败!" + e.getMessage());
			respLoanAppBean.setRetStCd(EsbBizEnums.RetCodeEnum.FAILURE.getVALUE());
			respLoanAppBean.setRtnMsg(e.getMessage());
		} catch (BizException e) {
			logger.error("马上申请审批服务接口处理失败!" + e.getMessage());
			respLoanAppBean.setRetStCd(EsbBizEnums.RetCodeEnum.FAILURE.getVALUE());
			respLoanAppBean.setRtnMsg(e.getMessage());
		} catch (Exception e) {
			logger.error("马上申请审批服务接口处理失败!" + e.getMessage());
			respLoanAppBean.setRetStCd(EsbBizEnums.RetCodeEnum.FAILURE.getVALUE());
			respLoanAppBean.setRtnMsg("系统异常!");
		}
		return respLoanAppBean;
	}

	@Autowired
	@Qualifier("nlsApplyInfoService")
	private NlsApplyInfoService nlsApplyInfoService;
	@Autowired
	@Qualifier("nlsApplyRelationService")
	private NlsApplyRelationService nlsApplyRelationService;
	@Autowired
	@Qualifier("nlsQueueTaskService")
	private NlsQueueTaskService nlsQueueTaskService;
	@Autowired
	@Qualifier("nlsProcessBizService")
	private NlsProcessBizService nlsProcessBizService;
	@Autowired
	@Qualifier("cusIndivService")
	private CusIndivService cusIndivService;
	@Autowired
	@Qualifier("prdInfoService")
	private PrdInfoService prdInfoService;
	@Autowired
	@Qualifier("prdAdaptedSoltService")
	private PrdAdaptedSoltService prdAdaptedSoltService;
	@Autowired
	@Qualifier("pubSysInfoService")
	private PubSysInfoService pubSysInfoService;
}
*/